<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class ControladorAutor extends ControladorFather{
    
    public $autor;
    
    public function __construct() {
        $this->autor = new Autor(host, dbname, port, user, pass);
    }
    
    public function index(){
        
    }
    
    public function listC($param = 0) {
        if ($param != "") {
            if ($param[0] == 0) {
                $result = $this->autor->find(array('order' => array('name')));
                include_once("View/Autor/listC.php");
            }
        }
    }
    
    public function add(){
        
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            
            $data = array(
                'name'=>$_POST['namePub']
            );
            
            if($this->autor->save(0,$data))
                $result = 1;
            else
                $result = 0;
        }
        include_once("View/Autor/add.php");
    }
    
     public function edit($param){
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            
            $data = array(
                'name'=>$_POST['nomePub']
            );
            
            if($this->autor->save($param[0],$data))
                $result = 1;
            else
                $result = 0;
        }
        $date = $this->autor->findById($param[0]);
        include_once("View/Autor/edit.php");
    }
    
    public function delete($param){
        
        $this->autor->delete($param[0]);
        header("Location: index.php?c=Autor&a=listC&p=0");
    }
}
?>